
#include "stdafx.h"
#include "WinMFCSystem.h"
#include "AppWinMFC.h"
#include "MainFrm.h"
#include "MFCSubClasses.h"
#include "ProjectPropertiesDlg.h"
#include "UserDefinedPropertyDlg.h"
#include "ChildView.h"
// #include "AddEntityWnd.h"
#include "memory"
//CAddEntityWnd  m_CAddEntityWnd;
CChildView     m_wndView;



const char NewSceneDefinition[] = "<OGITORSCENE>\n"
                                  "  <OBJECT type=\"%s\" scenemanagertype=\"%s\" name=\"SceneManager\" configfile=\"%s\" ambient=\"1.000 1.000 1.000\"></OBJECT>\n"
                                  "</OGITORSCENE>\n";


CChildView* CMainFrame::getChildView()
{
	return &m_wndView;
}
 
// CAddEntityWnd* CMainFrame::getCAddEntityWnd()
// {
// 	return &m_CAddEntityWnd;
// }
// CMainFrame

IMPLEMENT_DYNAMIC(CMainFrame, CFrameWndEx)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)
	ON_WM_CREATE()
	ON_WM_SETFOCUS()
	ON_WM_SIZING()
	ON_WM_CLOSE()
	ON_COMMAND(ID_HELP, OnHelp)
	ON_COMMAND(ID_FILE_NEW,OnFileNew)
    ON_COMMAND(ID_FILE_OPEN,OnFileOpen)
	ON_COMMAND(ID_FILE_SAVE,OnFileSave)
	ON_COMMAND(ID_FILE_SAVE_AS,OnFileSaveAs)
	ON_COMMAND(ID_FILE_CLOSE,OnFileClose)
	ON_COMMAND(ID_OPTIONSDLG,OnOptionsDlg)
    ON_UPDATE_COMMAND_UI(ID_OPTIONSDLG,OnUpdateOptionsDlg)
	ON_UPDATE_COMMAND_UI(ID_FILE_NEW,OnUpdateFileNew)
    ON_UPDATE_COMMAND_UI(ID_FILE_OPEN,OnUpdateFileOpen)
	ON_UPDATE_COMMAND_UI(ID_FILE_SAVE,OnUpdateFileSave)
	ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS,OnUpdateFileSaveAs)
	ON_UPDATE_COMMAND_UI(ID_FILE_CLOSE,OnUpdateFileClose)
	ON_COMMAND_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_OFF_2007_AQUA, &CMainFrame::OnApplicationLook)
	ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_APPLOOK_WIN_2000, ID_VIEW_APPLOOK_OFF_2007_AQUA, &CMainFrame::OnUpdateApplicationLook)
	ON_COMMAND(ID_VIEW_FPS,OnFPSCombo)
	ON_UPDATE_COMMAND_UI(ID_VIEW_FPS,OnUpdateFPSCombo)
	ON_COMMAND_RANGE(ID_TOOLS_SELECT, ID_TOOLS_SMOOTH, OnToolChange)
	ON_UPDATE_COMMAND_UI_RANGE(ID_TOOLS_SELECT, ID_TOOLS_SMOOTH, OnUpdateToolChange)
	ON_COMMAND_RANGE(ID_TOOLS_AXISX, ID_TOOLS_AXISZ, OnAxisChange)
	ON_UPDATE_COMMAND_UI_RANGE(ID_TOOLS_AXISX, ID_TOOLS_AXISZ, OnUpdateAxisChange)
	ON_COMMAND_RANGE(ID_OBJECTS_START, ID_OBJECTS_END, OnAddObject)
	ON_UPDATE_COMMAND_UI_RANGE(ID_OBJECTS_START, ID_OBJECTS_END, OnUpdateAddObject)
	ON_COMMAND_RANGE(ID_VIEW_PROPERTIES,ID_VIEW_ADDVIEWPORT, OnViewTab)
	ON_UPDATE_COMMAND_UI_RANGE(ID_VIEW_PROPERTIES,ID_VIEW_ADDVIEWPORT, OnUpdateViewTab)
	ON_UPDATE_COMMAND_UI(ID_VIEW_WINDOWS,OnUpdateViewMenu)
    ON_COMMAND(ID_ETL_BRUSHES,OnETLBrushChange)
    ON_COMMAND(ID_ETL_TEXTURES,OnETLTextureChange)
	ON_COMMAND(ID_ETL_COLORS,OnETLColorChange)
	ON_COMMAND(ID_ETL_CALCLIGHT,OnETLReLight)
	ON_COMMAND_RANGE(ID_ETL_BRUSHSIZE,ID_ETL_BRUSHINTENSITY,OnETLBrushOptionChange)
 

    ON_UPDATE_COMMAND_UI_RANGE(ID_ETL_CALCLIGHT,ID_ETL_BRUSHINTENSITY,OnUpdateETLBrushOptions)
	ON_UPDATE_COMMAND_UI_RANGE(ID_CAMERA_SAVE,ID_CAMERA_9,OnUpdateCameraOptions)
	ON_COMMAND_RANGE(ID_CAMERA_SAVE,ID_CAMERA_9,OnCameraOptions)
	ON_COMMAND_RANGE(ID_CAMERA_REMOVE_0,ID_CAMERA_REMOVE_9,OnCameraDelete)
	ON_COMMAND_RANGE(ID_TOOLS_FOCUS,ID_TOOLS_DELETE,OnEditorHotKey)
	ON_COMMAND_RANGE(ID_ADDUSERDEFINED,ID_EDITUSERDEFINED, OnUserDefinedProperty)
	ON_UPDATE_COMMAND_UI_RANGE(ID_ADDUSERDEFINED, ID_EDITUSERDEFINED, OnUpdateUserDefinedProperty)
	ON_UPDATE_COMMAND_UI_RANGE(ID_IMPORT_START, ID_IMPORT_END, OnUpdateImportPlugins)
	ON_COMMAND_RANGE(ID_EXPORT_START, ID_EXPORT_END, OnExportPlugins)
	ON_COMMAND_RANGE(ID_IMPORT_START, ID_IMPORT_END, OnImportPlugins)
	ON_UPDATE_COMMAND_UI_RANGE(ID_EXPORT_START, ID_EXPORT_END, OnUpdateExportPlugins)
	ON_UPDATE_COMMAND_UI_RANGE(ID_CONTEXTMENU_START, ID_CONTEXTMENU_END, OnUpdateExportPlugins)
	ON_UPDATE_COMMAND_UI(ID_FILE_IMPORT, OnUpdateImportPlugins)
	ON_UPDATE_COMMAND_UI(ID_FILE_EXPORT, OnUpdateExportPlugins)
	ON_COMMAND_RANGE(ID_OGITOR_UNDO,ID_OGITOR_REDO,OnUndoRedo)
    ON_UPDATE_COMMAND_UI_RANGE(ID_OGITOR_UNDO,ID_OGITOR_REDO,OnUpdateUndoRedo)
	ON_COMMAND_RANGE(ID_CUSTOMGUI_START,ID_CUSTOMGUI_END,OnCustomGUI)
    ON_UPDATE_COMMAND_UI_RANGE(ID_CUSTOMGUI_START,ID_CUSTOMGUI_END,OnUpdateCustomGUI)

	//ON_UPDATE_COMMAND_UI_RANGE(ID_MUSIC_BRUSHSIZE,ID_TOOLS_SETMUSIC,OnUpdateMusicGUI)
	//ON_COMMAND_RANGE(ID_MUSIC_BRUSHSIZE,ID_TOOLS_SETMUSIC,OnMusicGUI)
      
	ON_WM_TIMER()


END_MESSAGE_MAP()

// CMainFrame construction/destruction
//------------------------------------------------------------------------------------
CMainFrame::CMainFrame()
{
	 
	//m_playAvaterTime = 10;
	m_MusicLabel = NULL;
	theApp.m_nAppLook = theApp.GetInt(_T("ApplicationLook"), ID_VIEW_APPLOOK_OFF_2007_BLACK);
}
//------------------------------------------------------------------------------------
CMainFrame::~CMainFrame()
{
}

//------------------------------------------------------------------------------------
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWndEx::OnCreate(lpCreateStruct) == -1)
		return -1;
	//DlgEditMusic.Create(IDD_DIALOG_EDIT_MUSIC,this);

	SetTimer(1,500,NULL); 

	BOOL bNameValid;
	// set the visual manager and style based on persisted value
	OnApplicationLook(theApp.m_nAppLook);

	// create a view to occupy the client area of the frame
	if (!getChildView()->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
	{
		TRACE0("Failed to create view window\n");
		return -1;
	}

	m_wndRibbonBar.Create(this);
	m_wndRibbonBar.EnableKeyTips(FALSE);

	CreateDocumentColors();
	CreateImageCaches();
	m_BrushImages.SetImageSize(CSize(48,48));
	BOOL ret = m_BrushImages.Load(_T("..\\Data\\.cache\\Brushes.bmp"));
	m_TextureImages.SetImageSize(CSize(48,48));
	m_TextureImages.Load(_T("..\\Data\\.cache\\TTextures.bmp"));

	InitializeRibbon();

	if (!m_wndStatusBar.Create(this))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}

	CMFCToolBarImages images2;
	images2.SetImageSize(CSize(14, 14));
	images2.SetTransparentColor(RGB(0,0,0));
    images2.Load(IDB_CAMERAIMAGES);

	std::auto_ptr<CMFCRibbonButtonsGroup> apSBGroup2(new CMFCRibbonButtonsGroup);
	apSBGroup2->SetImages(&images2, NULL, NULL);
	
    CreateCameraMenu();	
	
	apSBGroup2->AddButton(m_CamBtn);
	m_wndStatusBar.AddElement(apSBGroup2.release(),_T("Camera Save/Load"));

	CString strTitlePane1;
	bNameValid = strTitlePane1.LoadString(IDS_STATUS_PANE1);
	ASSERT(bNameValid);
	m_wndStatusBar.AddElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_PANE1, _T("Camera Position:"), TRUE), _T("Camera Position:"));
	m_wndStatusBar.AddElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_PANE3, _T("Ogre FPS: -----"), TRUE), _T("Ogre FPS: -----"));

	int FPSState = theApp.GetInt(_T("OgreFPS"), 4);
	if(FPSState > 11) 
        FPSState = 4;
	CString strTemp;
	strTemp.Format(_T("FPS (%d)"),1000 / FPSLIST[FPSState]);

	m_FPSLabel = new CMFCRibbonStatusBarPane(ID_STATUSBAR_EXPANE1,strTemp,TRUE);
	m_wndStatusBar.AddExtendedElement(m_FPSLabel,_T("FPS (1000)"),TRUE);

	CMFCRibbonSlider* pFPS = new CMFCRibbonSlider(ID_VIEW_FPS,48);
	pFPS->SetRange(0,11);
	pFPS->SetPos(FPSState,1);
	pFPS->SetZoomIncrement(1);
    pFPS->SetZoomButtons(true);
	bNameValid = strTemp.LoadString(IDS_FPS_TIP);
	ASSERT(bNameValid);
	pFPS->SetToolTipText(strTemp);
	bNameValid = strTemp.LoadString(IDS_FPS_DESC);
	ASSERT(bNameValid);
	pFPS->SetDescription(strTemp);
	m_wndStatusBar.AddExtendedElement(pFPS,_T("FPS Slider"),TRUE);

	CMFCToolBarImages images;
	images.SetImageSize(CSize(14, 14));
	images.SetTransparentColor(RGB(0,0,0));

	std::auto_ptr<CMFCRibbonButtonsGroup> apSBGroup1(new CMFCRibbonButtonsGroup);
	if (images.Load(IDB_STATUSBAR))
	{
		apSBGroup1->SetImages(&images, NULL, NULL);
	}
	apSBGroup1->AddButton(new CMFCRibbonButton(ID_VIEW_BUILDERPLANE, _T(""), 0));
    apSBGroup1->AddButton(new CMFCRibbonButton(ID_VIEW_SCENEVIEW, _T(""), 1));
	apSBGroup1->AddButton(new CMFCRibbonButton(ID_VIEW_PROPERTIES, _T(""), 2));
	m_wndStatusBar.AddExtendedElement(apSBGroup1.release(), _T("View Shortcuts"));

	// enable Visual Studio 2005 style docking window behavior
	CDockingManager::SetDockingMode(DT_SMART);
	// enable Visual Studio 2005 style docking window auto-hide behavior
	EnableAutoHidePanes(CBRS_ALIGN_ANY);

	// Load menu item image (not placed on any standard toolbars):
	CMFCToolBar::AddToolBarForImageCollection(IDR_MENU_IMAGES_24, IDB_MENU_IMAGES_24);

	// create docking windows
	if (!CreateDockingWindows())
	{
		TRACE0("Failed to create docking windows\n");
		return -1;
	}

	m_wndSceneView.EnableDocking(CBRS_ALIGN_ANY);
	DockPane(&m_wndSceneView);
	m_wndProperties.EnableDocking(CBRS_ALIGN_ANY);
	DockPane(&m_wndProperties);
	//getCAddEntityWnd()->EnableDocking(CBRS_ALIGN_ANY);
	CDockablePane* pTabbedBar = NULL;
	//getCAddEntityWnd()->AttachToTabWnd(&m_wndProperties, DM_SHOW, TRUE, &pTabbedBar);
    
	return 0;
}
//------------------------------------------------------------------------------------
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWndEx::PreCreateWindow(cs) )
		return FALSE;

	cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
	cs.lpszClass = AfxRegisterWndClass(0);
	return TRUE;
}
//------------------------------------------------------------------------------------
void CMainFrame::InitializeRibbon()
{
	BOOL bNameValid;

	CString strTemp;
	bNameValid = strTemp.LoadString(IDS_RIBBON_FILE);
	ASSERT(bNameValid);

	// Load panel images:
	m_PanelImages.SetImageSize(CSize(16, 16));
	m_PanelImages.Load(IDB_BUTTONS);

	// Init main button:
	m_MainButton.SetImage(IDB_MAIN);
	m_MainButton.SetText(_T("\nf"));
	m_MainButton.SetToolTipText(strTemp);

	m_wndRibbonBar.SetApplicationButton(&m_MainButton, CSize (45, 45));
	CMFCRibbonMainPanel* pMainPanel = m_wndRibbonBar.AddMainCategory(strTemp, IDB_FILESMALL, IDB_FILELARGE);

	bNameValid = strTemp.LoadString(IDS_RIBBON_NEW);
	ASSERT(bNameValid);
	pMainPanel->Add(new CMFCRibbonButton(ID_FILE_NEW, strTemp, 0, 0));
	bNameValid = strTemp.LoadString(IDS_RIBBON_OPEN);
	ASSERT(bNameValid);
	pMainPanel->Add(new CMFCRibbonButton(ID_FILE_OPEN, strTemp, 1, 1));
	bNameValid = strTemp.LoadString(IDS_RIBBON_SAVE);
	ASSERT(bNameValid);
	pMainPanel->Add(new CMFCRibbonButton(ID_FILE_SAVE, strTemp, 2, 2));
	bNameValid = strTemp.LoadString(IDS_RIBBON_SAVEAS);
	ASSERT(bNameValid);
	pMainPanel->Add(new CMFCRibbonButton(ID_FILE_SAVE_AS, strTemp, 3, 3));

	bNameValid = strTemp.LoadString(IDS_RIBBON_CLOSE);
	ASSERT(bNameValid);
	pMainPanel->Add(new CMFCRibbonButton(ID_FILE_CLOSE, strTemp, 9, 9));

	bNameValid = strTemp.LoadString(IDS_RIBBON_RECENT_DOCS);
	ASSERT(bNameValid);
	pMainPanel->AddRecentFilesList(strTemp);

	bNameValid = strTemp.LoadString(IDS_RIBBON_EXIT);
	ASSERT(bNameValid);
	pMainPanel->AddToBottom(new CMFCRibbonMainPanelButton(ID_APP_EXIT, strTemp, 15));


	CreateHomeCategory();
	CreateETLToolsCategory();
	CreateMusicToolsCategory();
    CreateCustomCategories();

	// Add elements to the right side of tabs:
	bNameValid = strTemp.LoadString(IDS_RIBBON_STYLE);
	ASSERT(bNameValid);
	CMFCRibbonButton* pVisualStyleButton = new CMFCRibbonButton(-1, strTemp, -1, -1);

	pVisualStyleButton->SetMenu(IDR_THEME_MENU, FALSE /* No default command */, TRUE /* Right align */);

	bNameValid = strTemp.LoadString(IDS_RIBBON_STYLE_TIP);
	ASSERT(bNameValid);
	pVisualStyleButton->SetToolTipText(strTemp);
	bNameValid = strTemp.LoadString(IDS_RIBBON_STYLE_DESC);
	ASSERT(bNameValid);
	pVisualStyleButton->SetDescription(strTemp);
	m_wndRibbonBar.AddToTabs(pVisualStyleButton);

	// Add quick access toolbar commands:
	CList<UINT, UINT> lstQATCmds;

	lstQATCmds.AddTail(ID_FILE_NEW);
	lstQATCmds.AddTail(ID_FILE_OPEN);
	lstQATCmds.AddTail(ID_FILE_SAVE);

	m_wndRibbonBar.SetQuickAccessCommands(lstQATCmds);

	m_wndRibbonBar.AddToTabs(new CMFCRibbonButton(ID_APP_ABOUT, _T("\na"), m_PanelImages.ExtractIcon (28)));
	m_wndRibbonBar.AddToTabs(new CMFCRibbonButton(ID_HELP, _T("\na"), m_PanelImages.ExtractIcon (0)));
}
//------------------------------------------------------------------------------------
BOOL CMainFrame::CreateDockingWindows()
{
	BOOL bNameValid;

	// Create class view
	CString strSceneView;
	bNameValid = strSceneView.LoadString(IDS_SCENE_VIEW);
	ASSERT(bNameValid);
	if (!m_wndSceneView.Create(strSceneView, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_SCENEVIEW, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_LEFT | CBRS_FLOAT_MULTI))
	{
		TRACE0("Failed to create Scene View window\n");
		return FALSE; // failed to create
	}

	// Create properties window
	CString strPropertiesWnd;
	bNameValid = strPropertiesWnd.LoadString(IDS_PROPERTIES_WND);
	ASSERT(bNameValid);
	if (!m_wndProperties.Create(strPropertiesWnd, this, CRect(0, 0, 200, 200), TRUE, ID_VIEW_PROPERTIES, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_RIGHT | CBRS_FLOAT_MULTI))
	{
		TRACE0("Failed to create Properties window\n");
		return FALSE; // failed to create
	}

	CString strAddEntity;
	bNameValid = strAddEntity.LoadString(IDS_ADDENTITY);
	ASSERT(bNameValid);
// 	if (!getCAddEntityWnd()->Create(strAddEntity, this, CRect(0, 0, 450, 250), TRUE, ID_VIEW_ADDENTITY, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | CBRS_RIGHT | CBRS_FLOAT_MULTI))
// 	{
// 		TRACE0("Failed to create Add Entity window\n");
// 		return FALSE; // failed to create
// 	}
	//m_ManagerCDockablePane.CreateDockingWindows(&m_wndProperties);
	SetDockingWindowIcons(theApp.m_bHiColorIcons);
	return TRUE;
}
//------------------------------------------------------------------------------------
void CMainFrame::SetDockingWindowIcons(BOOL bHiColorIcons)
{
	HICON hSceneViewIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_SCENE_VIEW_HC), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);
	m_wndSceneView.SetIcon(hSceneViewIcon, FALSE);

	HICON hPropertiesBarIcon = (HICON) ::LoadImage(::AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_PROPERTIES_WND_HC), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);
	m_wndProperties.SetIcon(hPropertiesBarIcon, FALSE);
}
//------------------------------------------------------------------------------------
// CMainFrame diagnostics
//------------------------------------------------------------------------------------
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWndEx::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWndEx::Dump(dc);
}
#endif //_DEBUG

//------------------------------------------------------------------------------------
// CMainFrame message handlers
//------------------------------------------------------------------------------------
void CMainFrame::OnSetFocus(CWnd* /*pOldWnd*/)
{
	getChildView()->SetFocus();
}
//------------------------------------------------------------------------------------
void CMainFrame::OnSizing(UINT nSide,LPRECT lpRect)
{
	CFrameWndEx::OnSizing(nSide,lpRect);
}
//------------------------------------------------------------------------------------
BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
	// let the view have first crack at the command
	if (getChildView()->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
		return TRUE;

	// otherwise, do default handling
	return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
//------------------------------------------------------------------------------------
void CMainFrame::OnApplicationLook(UINT id)
{
	CWaitCursor wait;

	theApp.m_nAppLook = id;

	switch (theApp.m_nAppLook)
	{
		case ID_VIEW_APPLOOK_OFF_2007_BLUE:
			CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_LunaBlue);
			break;

		case ID_VIEW_APPLOOK_OFF_2007_BLACK:
			CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_ObsidianBlack);
			break;

		case ID_VIEW_APPLOOK_OFF_2007_SILVER:
			CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Silver);
			break;

		case ID_VIEW_APPLOOK_OFF_2007_AQUA:
			CMFCVisualManagerOffice2007::SetStyle(CMFCVisualManagerOffice2007::Office2007_Aqua);
			break;
	}

	CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerOffice2007));
	CDockingManager::SetDockingMode(DT_SMART);

	RedrawWindow(NULL, NULL, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW | RDW_FRAME | RDW_ERASE);
	theApp.WriteInt(_T("ApplicationLook"), theApp.m_nAppLook);
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateApplicationLook(CCmdUI* pCmdUI)
{
	pCmdUI->SetRadio(theApp.m_nAppLook == pCmdUI->m_nID);
}
//------------------------------------------------------------------------------------
void CMainFrame::OnToolChange(UINT id)
{
//     CViewportEditor *ovp = gClientRootGetViewport();
//     if(ovp)
//         ovp->SetEditorTool(id - ID_TOOLS_SELECT);
// 
//     switch(id)
//     {
//     case ID_TOOLS_DEFORM:
//     case ID_TOOLS_SPLAT:
//     case ID_TOOLS_PAINT:
//     case ID_TOOLS_SMOOTH:
// 	    theApp.m_OgitorsRoot->GetTerrainEditor()->SetEditMode(id - ID_TOOLS_DEFORM + 1);
//     }
//     getChildView()->SetFocus();
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateToolChange(CCmdUI* pCmdUI)
{
//     CViewportEditor *ovp = gClientRootGetViewport();
//     unsigned int EditorTool = 0; 
//     if(ovp)
//         EditorTool = ovp->GetEditorTool();
// 
//     if(!theApp.m_OgitorsRoot->IsSceneLoaded())
//     {
//         pCmdUI->Enable(0);
//         return;
//     }
//     switch(pCmdUI->m_nID)
//     {
//     case ID_TOOLS_SELECT:
//     case ID_TOOLS_MOVE:
//     case ID_TOOLS_ROTATE:
//     case ID_TOOLS_SCALE:  pCmdUI->SetCheck((EditorTool + ID_TOOLS_SELECT) == pCmdUI->m_nID);break;
//     case ID_TOOLS_DEFORM:
//     case ID_TOOLS_SPLAT:
//     case ID_TOOLS_PAINT:
//     case ID_TOOLS_SMOOTH:
// 	    pCmdUI->Enable(theApp.m_OgitorsRoot->GetSelected() && theApp.m_OgitorsRoot->GetSelected()->IsTerrainType() && theApp.m_OgitorsRoot->IsSceneLoaded());
//         pCmdUI->SetCheck(theApp.m_OgitorsRoot->GetTerrainEditor() && (theApp.m_OgitorsRoot->GetTerrainEditor()->GetEditMode() + ID_TOOLS_DEFORM - 1) == pCmdUI->m_nID);
//     }
}
//------------------------------------------------------------------------------------
void CMainFrame::OnETLBrushChange()
{
//     int id = m_BrushGallery->GetSelectedItem();
//     theApp.m_OgitorsRoot->GetTerrainEditor()->SetBrush(m_BrushNames[id]);
//     getChildView()->SetFocus();
}
//------------------------------------------------------------------------------------
void CMainFrame::OnETLTextureChange()
{
//     int id = m_TTextureGallery->GetSelectedItem();
//     theApp.m_OgitorsRoot->GetTerrainEditor()->SetTexture(m_TTextureNames[id]);
//     getChildView()->SetFocus();
}
//------------------------------------------------------------------------------------
void CMainFrame::OnETLColorChange()
{
//     ColourValue colval;
//     COLORREF cr = GetColorFromColorButton(ID_ETL_COLORS);
//     colval.setAsABGR(cr);
//     theApp.m_OgitorsRoot->GetTerrainEditor()->SetColour(colval);
//     getChildView()->SetFocus();
}
//------------------------------------------------------------------------------------
void CMainFrame::OnETLBrushOptionChange(UINT id)
{
//     float state = BrushValueTable[GetSliderState(id)];
//     CString newlabel;
//     switch(id)
//     {
//     case ID_ETL_BRUSHSIZE:
//         {
//             theApp.m_OgitorsRoot->GetTerrainEditor()->SetBrushSize(state);
//             if(state > 99)
//                 newlabel.Format(_T("Size (%d)"),(int)state);
//             else
//                 newlabel.Format(_T("Size ( %d )"),(int)state);
//             m_BrushSizeLabel->SetText(newlabel);
//             m_BrushSizeLabel->Redraw();
//             break;
//         }
//     case ID_ETL_BRUSHINTENSITY:
//         {
//             theApp.m_OgitorsRoot->GetTerrainEditor()->SetBrushIntensity(state / 5.0f);
//             if(state > 99)
//                 newlabel.Format(_T("Intensity (%d)"),(int)state);
//             else
//                 newlabel.Format(_T("Intensity ( %d )"),(int)state);
//             m_BrushIntensityLabel->SetText(newlabel);
//             m_BrushIntensityLabel->Redraw();
//             break;
//         }
//     }
//     getChildView()->SetFocus();
}
//------------------------------------------------------------------------------------
void CMainFrame::OnETLReLight()
{
//     theApp.m_OgitorsRoot->GetTerrainEditor()->CalculateLightMap();
//     getChildView()->SetFocus();
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateETLBrushOptions(CCmdUI *pCmdUI)
{
   // pCmdUI->Enable(theApp.m_OgitorsRoot->GetSelected() && theApp.m_OgitorsRoot->GetSelected()->IsTerrainType() && theApp.m_OgitorsRoot->IsSceneLoaded());
}
//------------------------------------------------------------------------------------
void CMainFrame::OnAxisChange(UINT id)
{
//      int iAxis = (1 << (id - ID_TOOLS_AXISX));
//      CViewportEditor *ovp = gClientRootGetViewport();
//      unsigned int EditorAxis = 0;
//      if(ovp)
//          EditorAxis = ovp->GetEditorAxis();
// 
//      if(EditorAxis & iAxis)
//          EditorAxis -= iAxis;
// 	 else
//          EditorAxis += iAxis;
// 
//      if(ovp)
//          ovp->SetEditorAxis(EditorAxis);
// 
//     getChildView()->SetFocus();
// 	theApp.m_OgitorsRoot->HiLiteWidget(EditorAxis);
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateAxisChange(CCmdUI* pCmdUI)
{
//     if(!theApp.m_OgitorsRoot->IsSceneLoaded())
//     {
//         pCmdUI->Enable(0);
//         return;
//     }
//     int iAxis = (1 << (pCmdUI->m_nID - ID_TOOLS_AXISX));
//     CViewportEditor *ovp = gClientRootGetViewport();
//     unsigned int EditorAxis = 0;
//     if(ovp)
//          EditorAxis = ovp->GetEditorAxis();
// 	pCmdUI->SetRadio(EditorAxis & iAxis);
}
//------------------------------------------------------------------------------------
void CMainFrame::OnFPSCombo()
{
    CMFCRibbonSlider* pSlider = (CMFCRibbonSlider*)m_wndStatusBar.GetExElement(1);
    int state = pSlider->GetPos();
    theApp.m_FPSID = state;
    theApp.WriteInt(_T("OgreFPS"), theApp.m_FPSID);
    theApp.m_FPSTimer = FPSLIST[state];
    CString newlabel;
    newlabel.Format(_T("FPS (%d)"),1000 / FPSLIST[state]);
    m_FPSLabel->SetText(newlabel);
    m_wndStatusBar.RecalcLayout();
    m_FPSLabel->Redraw();
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateFPSCombo(CCmdUI* pCmdUI)
{
   // pCmdUI->Enable(theApp.m_OgitorsRoot->IsSceneLoaded());
}
//------------------------------------------------------------------------------------
void CMainFrame::OnFileNew()
{
//     if(!(theApp.m_OgitorsRoot->TerminateScene())) 
//         return;
//  
//     CreateNewProjectOptions();
//     CProjectPropertiesSheet *pPropSheet  = new CProjectPropertiesSheet(_T("New Scene Settings"),CMFCPropertySheet::PropSheetLook_List,theApp.m_OgitorsRoot->GetProjectOptions());
//     if(pPropSheet->DoModal() == IDOK)
//     {
//         CreateNewSceneFile();
//         String newscenefile = theApp.m_OgitorsRoot->GetProjectOptions()->ProjectDir + theApp.m_OgitorsRoot->GetProjectOptions()->ProjectName + ".ogscene";
//         CString filename(newscenefile.c_str());
//         theApp.m_OgitorsRoot->LoadScene(ConvertToApoString(filename));
//     }
//  
//     delete pPropSheet;
//     getChildView()->SetFocus();
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateFileNew(CCmdUI* pCmdUI)
{
    pCmdUI->Enable(TRUE);
}
//------------------------------------------------------------------------------------
void CMainFrame::OnOptionsDlg()
{
    CProjectPropertiesSheet *pPropSheet  = new CProjectPropertiesSheet(_T("Scene Settings"),CMFCPropertySheet::PropSheetLook_List,theApp.m_OgitorsRoot->GetProjectOptions());
    if(pPropSheet->DoModal() == IDOK)
    {
        ::SendMessage(getChildView()->GetSafeHwnd(),WM_RELOADUSERRESOURCES,0,0);
    }

    delete pPropSheet;
    getChildView()->SetFocus();
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateOptionsDlg(CCmdUI* pCmdUI)
{
   // pCmdUI->Enable(theApp.m_OgitorsRoot->IsSceneLoaded());
}
//------------------------------------------------------------------------------------
void CMainFrame::OnFileOpen()
{
//     if(!(theApp.m_OgitorsRoot->TerminateScene())) 
//         return;
//     int ret = theApp.m_OgitorsRoot->LoadScene("");
//     if(ret == SCF_CANCEL) 
//         return;
//     if( ret != SCF_OK )
//     {
//         AfxMessageBox(_T("Error Loading file"),MB_OK);
//         return;
//     }
//     getChildView()->SetFocus();
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateFileOpen(CCmdUI* pCmdUI)
{
    pCmdUI->Enable(TRUE);
}
//------------------------------------------------------------------------------------
void CMainFrame::OnFileSave()
{
//     theApp.m_OgitorsRoot->SaveScene(false);
//     getChildView()->SetFocus();
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateFileSave(CCmdUI* pCmdUI)
{
   // pCmdUI->Enable(theApp.m_OgitorsRoot->IsSceneModified());
}
//------------------------------------------------------------------------------------
void CMainFrame::OnFileSaveAs()
{
//      theApp.m_OgitorsRoot->SaveScene(true);
//      getChildView()->SetFocus();
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateFileSaveAs(CCmdUI* pCmdUI)
{
   //  pCmdUI->Enable(theApp.m_OgitorsRoot->IsSceneLoaded());
}
//------------------------------------------------------------------------------------
void CMainFrame::OnFileClose()
{
   //  theApp.m_OgitorsRoot->TerminateScene();
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateFileClose(CCmdUI* pCmdUI)
{
   //  pCmdUI->Enable(theApp.m_OgitorsRoot->IsSceneLoaded());
}
//------------------------------------------------------------------------------------
void CMainFrame::OnAddObject(UINT id)
{
//     NameValuePairList params;
//     params["init"] = true;
//   
//     int typeID = id - ID_OBJECTS_START;
//   
//     StringVector objectList = theApp.m_OgitorsRoot->GetSortedTypeList();
//     OGITORREGISTRATIONSTRUCT *data = theApp.m_OgitorsRoot->GetTypeData(objectList[typeID]);
//     CViewportEditor *ovp = gClientRootGetViewport();
// 
//     if(data->TypeName == "Entity Object")
//         ShowPane(&getCAddEntityWnd(),true,false,true);
//     else if(data->RequirePlacement)
//     {
//         if(ovp)
//             ovp->TryAddObject(data->TypeName,"");
//     }
//     else
// 	    theApp.m_OgitorsRoot->CreateEditorObject(0,data->TypeName,params,true,true);
// 
//   getChildView()->SetFocus();
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateAddObject(CCmdUI* pCmdUI)
{
//     int typeID = pCmdUI->m_nID - ID_OBJECTS_START;
//   
//     StringVector objectList = theApp.m_OgitorsRoot->GetSortedTypeList();
//     OGITORREGISTRATIONSTRUCT *data = theApp.m_OgitorsRoot->GetTypeData(objectList[typeID]);
// 
//     pCmdUI->Enable(theApp.m_OgitorsRoot->IsSceneLoaded() && theApp.m_OgitorsRoot->CanInstantiateObject(data->TypeName));
}
//------------------------------------------------------------------------------------
void CMainFrame::OnViewTab(UINT id)
{
// 	switch(id)
// 	{
// 	case ID_VIEW_ADDVIEWPORT:
// 	    {
//             NameValuePairList params;
//             gClientRootCreateEditorObject(0,"Viewport Object",params,true,true);
// 		    break;
// 	    }
// 	case ID_VIEW_PROPERTIES:
// 	    {
// 	        ShowPane(&m_wndProperties,!m_wndProperties.IsVisible(),false,false);
// 		    break;
// 	    }
// 	case ID_VIEW_SCENEVIEW:
// 	    {
// 		    ShowPane(&m_wndSceneView,!m_wndSceneView.IsVisible(),false,false);
// 	        break;
// 	    }
// 	case ID_VIEW_BUILDERPLANE:
// 	    {
//             CViewportEditor *ovp = gClientRootGetViewport();
// 		    if(ovp)
//                 ovp->ShowGrid();
// 		    break;
// 	    }
// 	}
//     getChildView()->SetFocus();
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateViewTab(CCmdUI *pCmdUI)
{
// 	switch(pCmdUI->m_nID)
// 	{
// 	case ID_VIEW_ADDVIEWPORT:
// 	    {
//             pCmdUI->Enable(gClientRootIsSceneLoaded());
// 		    break;
// 	    }
// 	case ID_VIEW_PROPERTIES:
// 	    {
// 		    pCmdUI->SetCheck(m_wndProperties.IsVisible());
// 		    break;
// 	    }
// 	case ID_VIEW_SCENEVIEW:
// 	    {
// 		    pCmdUI->SetCheck(m_wndSceneView.IsVisible());
// 		    break;
// 	    }
// 	case ID_VIEW_BUILDERPLANE:
// 	    {
//             CViewportEditor *ovp = gClientRootGetViewport();
//             if(ovp)
//             {
//                  pCmdUI->SetCheck(ovp->IsGridVisible());
//                  pCmdUI->Enable(1);
//             }
//             else
//             {
//                  pCmdUI->SetCheck(0);
//                  pCmdUI->Enable(0);
//             }
//             break;
// 	    }
// 	}
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateViewMenu(CCmdUI *pCmdUI)
{
    pCmdUI->Enable();
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateCameraOptions(CCmdUI *pCmdUI)
{
//     PROJECTOPTIONS *pOpt = theApp.m_OgitorsRoot->GetProjectOptions();
//     PolygonMode polymode = PM_SOLID;
//     if(gClientRootGetViewport())
//         polymode = gClientRootGetViewport()->GetCameraEditor()->GetCamera()->getPolygonMode();
//     if(!theApp.m_OgitorsRoot->IsSceneLoaded()) 
//     {	  
// 	    pCmdUI->Enable(0);
// 	    return;
//     }
//   
//     CViewportEditor *ovp = gClientRootGetViewport();
//     float CameraSpeed = 0.0f;
//     if(ovp)
//         CameraSpeed = ovp->GetCameraSpeed();
//     switch(pCmdUI->m_nID)
//     {
//     case ID_CAMERA_SAVE:pCmdUI->Enable(pOpt->CameraSaveCount != 10);break;
//     case ID_CAMERA_SPEED_INCREASE:pCmdUI->Enable(1);break;
//     case ID_CAMERA_SPEED_DECREASE:pCmdUI->Enable(CameraSpeed > 1.0f);break;
//     case ID_CAMERA_MODE_SOLID:pCmdUI->Enable(1);pCmdUI->SetRadio(polymode == PM_SOLID);break;
//     case ID_CAMERA_MODE_WIREFRAME:pCmdUI->Enable(1);pCmdUI->SetRadio(polymode == PM_WIREFRAME);break;
//     case ID_CAMERA_MODE_POINT:pCmdUI->Enable(1);pCmdUI->SetRadio(polymode == PM_POINTS);break;
//     case ID_CAMERA_0:
//     case ID_CAMERA_REMOVE_0:pCmdUI->Enable(pOpt->CameraSaveCount > 0);break;
//     case ID_CAMERA_1:
//     case ID_CAMERA_REMOVE_1:pCmdUI->Enable(pOpt->CameraSaveCount > 1);break;
//     case ID_CAMERA_2:
//     case ID_CAMERA_REMOVE_2:pCmdUI->Enable(pOpt->CameraSaveCount > 2);break;
//     case ID_CAMERA_3:
//     case ID_CAMERA_REMOVE_3:pCmdUI->Enable(pOpt->CameraSaveCount > 3);break;
//     case ID_CAMERA_4:
//     case ID_CAMERA_REMOVE_4:pCmdUI->Enable(pOpt->CameraSaveCount > 4);break;
//     case ID_CAMERA_5:
//     case ID_CAMERA_REMOVE_5:pCmdUI->Enable(pOpt->CameraSaveCount > 5);break;
//     case ID_CAMERA_6:
//     case ID_CAMERA_REMOVE_6:pCmdUI->Enable(pOpt->CameraSaveCount > 6);break;
//     case ID_CAMERA_7:
//     case ID_CAMERA_REMOVE_7:pCmdUI->Enable(pOpt->CameraSaveCount > 7);break;
//     case ID_CAMERA_8:
//     case ID_CAMERA_REMOVE_8:pCmdUI->Enable(pOpt->CameraSaveCount > 8);break;
//     case ID_CAMERA_9:
//     case ID_CAMERA_REMOVE_9:pCmdUI->Enable(pOpt->CameraSaveCount > 9);break;
//     }
}
//------------------------------------------------------------------------------------
void CMainFrame::OnClose()
{
//     if(theApp.m_OgitorsRoot->TerminateScene())
//     {
//         CFrameWndEx::OnClose();
//     }
}
//------------------------------------------------------------------------------------
void CMainFrame::OnCameraOptions(UINT id)
{
//    PROJECTOPTIONS *pOpt = theApp.m_OgitorsRoot->GetProjectOptions();
//    CViewportEditor *ovp = gClientRootGetViewport();
//  
//     switch(id)
//     {
//     case ID_CAMERA_SAVE:SaveCamPos();break;
//     case ID_CAMERA_SPEED_INCREASE:if(ovp) ovp->MultiplyCameraSpeed(1.2f);break;
//     case ID_CAMERA_SPEED_DECREASE:if(ovp) ovp->MultiplyCameraSpeed(1.0f / 1.2f);break;
//     case ID_CAMERA_MODE_SOLID:getChildView()->SetCameraMode(PM_SOLID);break;
//     case ID_CAMERA_MODE_WIREFRAME:getChildView()->SetCameraMode(PM_WIREFRAME);break;
//     case ID_CAMERA_MODE_POINT:getChildView()->SetCameraMode(PM_POINTS);break;
//     default:
//         {
//             int pos = id - ID_CAMERA_0;
//             if(theApp.m_OgitorsRoot->GetViewport()->GetCameraEditor()->GetCamera() && pos < pOpt->CameraSaveCount)
// 	        {
// 		        theApp.m_OgitorsRoot->GetViewport()->GetCameraEditor()->GetCamera()->setPosition(pOpt->CameraPositions[pos]);
// 		        theApp.m_OgitorsRoot->GetViewport()->GetCameraEditor()->GetCamera()->setOrientation(pOpt->CameraOrientations[pos]);
// 	        }
// 	    }
//     }
//     getChildView()->SetFocus();
}
//------------------------------------------------------------------------------------
void CMainFrame::OnCameraDelete(UINT id)
{
    DeleteCamPos(id - ID_CAMERA_REMOVE_0);
    getChildView()->SetFocus();
}
//------------------------------------------------------------------------------------
void CMainFrame::SaveCamPos()
{
//     PROJECTOPTIONS *pOpt = theApp.m_OgitorsRoot->GetProjectOptions();
// 	if(pOpt->CameraSaveCount == 10) 
//         return;
// 	if(!(theApp.m_OgitorsRoot->GetViewport()->GetCameraEditor()->GetCamera())) 
//         return;
// 
// 	pOpt->CameraPositions[pOpt->CameraSaveCount] = theApp.m_OgitorsRoot->GetViewport()->GetCameraEditor()->GetCamera()->getDerivedPosition();
// 	pOpt->CameraOrientations[pOpt->CameraSaveCount] = theApp.m_OgitorsRoot->GetViewport()->GetCameraEditor()->GetCamera()->getDerivedOrientation();
//     
// 	CString menustr;
//     menustr.Format(_T("Camera %d: <%.1f,%.1f,%.1f>"),pOpt->CameraSaveCount,pOpt->CameraPositions[pOpt->CameraSaveCount].x,pOpt->CameraPositions[pOpt->CameraSaveCount].y,pOpt->CameraPositions[pOpt->CameraSaveCount].z);
// 	m_CamBtn->GetSubItems().GetAt(pOpt->CameraSaveCount)->SetText(menustr);
// 	pOpt->CameraSaveCount++;
}
//------------------------------------------------------------------------------------
void CMainFrame::DeleteCamPos(int Index)
{
//     PROJECTOPTIONS *pOpt = theApp.m_OgitorsRoot->GetProjectOptions();
// 	if(pOpt->CameraSaveCount == 0) 
//         return;
// 	if(!(theApp.m_OgitorsRoot->GetViewport()->GetCameraEditor()->GetCamera())) 
//         return;
// 
// 	for(int i =Index;i < pOpt->CameraSaveCount;i++)
// 	{
// 	    pOpt->CameraPositions[i] = pOpt->CameraPositions[i + 1];
// 	    pOpt->CameraOrientations[i] = pOpt->CameraOrientations[i + 1];
// 	    CString menustr;
//         menustr.Format(_T("Camera %d: <%.1f,%.1f,%.1f>"),i,pOpt->CameraPositions[i].x,pOpt->CameraPositions[i].y,pOpt->CameraPositions[i].z);
// 	    m_CamBtn->GetSubItems().GetAt(i)->SetText(menustr);
// 	}
//     m_CamBtn->GetSubItems().GetAt(pOpt->CameraSaveCount - 1)->SetText(_T("(Empty)"));
// 	pOpt->CameraSaveCount--;
}
//------------------------------------------------------------------------------------
void CMainFrame::SetCameraPositions()
{
//     PROJECTOPTIONS *pOpt = theApp.m_OgitorsRoot->GetProjectOptions();
// 
//     for(int i =0;i < pOpt->CameraSaveCount;i++)
//     {
//         CString menustr;
//         menustr.Format(_T("Camera %d: <%.1f,%.1f,%.1f>"),i,pOpt->CameraPositions[i].x,pOpt->CameraPositions[i].y,pOpt->CameraPositions[i].z);
//         m_CamBtn->GetSubItems().GetAt(i)->SetText(menustr);
//     }
//     for(int i = pOpt->CameraSaveCount;i < 10;i++)
//     {
//         m_CamBtn->GetSubItems().GetAt(i)->SetText(_T("(Empty)"));
//     }
}
//------------------------------------------------------------------------------------
void CMainFrame::OnEditorHotKey(UINT id)
{
//     CViewportEditor *ovp = gClientRootGetViewport();
//  
//     switch(id)
//     {
//     case ID_TOOLS_FOCUS:if(ovp) ovp->FocusSelectedObject();break;
//     case ID_TOOLS_DELETE:if(ovp) ovp->DeleteSelectedObject();break;
//     }
}
//------------------------------------------------------------------------------------
void CMainFrame::OnHelp()
{
	::HtmlHelp(GetSafeHwnd(),_T("Ogitor.chm::Introduction.htm"),HH_DISPLAY_TOPIC,NULL);
}
//------------------------------------------------------------------------------------
void CMainFrame::CreateNewProjectOptions()
{
//     TCHAR buffer[500];
// 
//     GetModuleFileName(NULL,buffer,500);
// 
//     PROJECTOPTIONS *pOpt = theApp.m_OgitorsRoot->GetProjectOptions();
// 
//     pOpt->IsNewProject = true;
//     pOpt->ProjectName = "<Enter New Name>";
//     pOpt->ProjectDir = ConvertToApoString(ExtractFilePath(buffer));
//     pOpt->CreatedIn = pOpt->ProjectDir;
//     pOpt->SceneManagerName = "OctreeSceneManager";
//     pOpt->ETLDirectory = "ETL";
//     pOpt->HydraxDirectory = "Hydrax";
//     pOpt->CaelumDirectory = "Caelum";
//     pOpt->PagedGeometryDirectory = "PagedGeometry";
//     pOpt->SceneManagerConfigFile = "";
//     pOpt->CameraSaveCount = 0;
//     pOpt->ResourceDirectories.clear();
}
//------------------------------------------------------------------------------------
void CMainFrame::CreateNewSceneFile()
{
//     char buffer[5000];
//     String filename = theApp.m_OgitorsRoot->GetProjectOptions()->ProjectDir + theApp.m_OgitorsRoot->GetProjectOptions()->ProjectName + ".ogscene";
//     std::ofstream outfile(filename.c_str());
//     outfile << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
//     theApp.m_OgitorsRoot->WriteProjectOptions(outfile,true);
//     sprintf_s(buffer,5000,NewSceneDefinition,theApp.m_OgitorsRoot->GetProjectOptions()->SceneManagerName.c_str(),theApp.m_OgitorsRoot->GetProjectOptions()->SceneManagerName.c_str(),theApp.m_OgitorsRoot->GetProjectOptions()->SceneManagerConfigFile.c_str());
//     outfile << buffer;
//     outfile.close();
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUserDefinedProperty(UINT id)
{
//     if(id == ID_ADDUSERDEFINED)
//     {
//         CUserDefinedPropertyDlg dlg(theApp.GetMainWnd(),theApp.m_OgitorsRoot->GetSelected()->GetEditorType());
// 
//         if(dlg.DoModal() == IDOK)
//         {
//              CBaseEditor *ed = theApp.m_OgitorsRoot->GetSelected();
//              if(m_wndProperties.m_CurrentProperty)
//              {
//                  ed->AddCustomProperty(m_wndProperties.m_CurrentProperty->GetData(),dlg.m_Name,dlg.m_TypeName);
//              }
//              else
//                  ed->AddCustomProperty(dlg.m_Name,dlg.m_TypeName);
//              
//              ed->SetSelected(false);
//              ed->SetSelected(true);
//         }
//     }
//     else if(id == ID_DELETEUSERDEFINED)
//     {
//         CBaseEditor *ed = theApp.m_OgitorsRoot->GetSelected();
//         ed->DeleteCustomProperty(m_wndProperties.m_CurrentProperty->GetData());
// 	    ed->SetSelected(false);
// 	    ed->SetSelected(true);
//     }
//     else
//     {
//     }
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateUserDefinedProperty(CCmdUI* pCmdUI)
{
    switch(pCmdUI->m_nID)
    {
    case ID_ADDUSERDEFINED:pCmdUI->Enable(TRUE);return;
    case ID_DELETEUSERDEFINED:
    case ID_EDITUSERDEFINED:pCmdUI->Enable((int)m_wndProperties.m_CurrentProperty);return;
    }

    pCmdUI->Enable(TRUE);
}
//------------------------------------------------------------------------------------
// void CMainFrame::UpdateTerrainOptions(CTerrainEditor *terrain)
// {
//     int id = m_BrushGallery->GetSelectedItem();
//     terrain->SetBrush(m_BrushNames[id]);
// 
//     id = m_TTextureGallery->GetSelectedItem();
//     terrain->SetTexture(m_TTextureNames[id]);
// 
//     ColourValue colval;
//     COLORREF cr = GetColorFromColorButton(ID_ETL_COLORS);
//     colval.setAsABGR(cr);
//     terrain->SetColour(colval);
// 
//     float state = BrushValueTable[GetSliderState(ID_ETL_BRUSHSIZE)];
//     terrain->SetBrushSize(state);
// 
//     state = BrushValueTable[GetSliderState(ID_ETL_BRUSHINTENSITY)];
//     terrain->SetBrushIntensity(state / 5.0f);
//     terrain->SetEditMode(0);
/*}*/
//------------------------------------------------------------------------------------
void CMainFrame::OnImportPlugins(UINT id)
{
//     CMFCRibbonButton *Btn = (CMFCRibbonButton*)m_wndRibbonBar.FindByID(id,FALSE);
//     if(Btn)
//     {
//         try
//         {
//             theApp.m_OgitorsRoot->TriggerImportSerializer(ConvertToApoString(Btn->GetText()));
//         }
// //         catch(...)
// //         {
// //             AfxMessageBox( _T("An Error Occured trying to Import File"), MB_OK );
// //         }
// 
// 		catch (Exception& e)
// 		{
// 			MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_ICONERROR | MB_TASKMODAL);
// 		}
//     }
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateImportPlugins(CCmdUI *pCmdUI)
{
    pCmdUI->Enable(TRUE);
}
//------------------------------------------------------------------------------------
void CMainFrame::OnExportPlugins(UINT id)
{
//     CMFCRibbonButton *Btn = (CMFCRibbonButton*)m_wndRibbonBar.FindByID(id,FALSE);
//     if(Btn)
//     {
//         try
//         {
//             theApp.m_OgitorsRoot->TriggerExportSerializer(ConvertToApoString(Btn->GetText()));
//         }
// //         catch(...)
// //         {
// //             AfxMessageBox( _T("An Error Occured trying to Export File"), MB_OK );
// //         }
// 		catch (Exception& e)
// 		{
// 			MessageBoxA(NULL, e.getFullDescription().c_str(), "An exception has occurred!", MB_ICONERROR | MB_TASKMODAL);
// 		}
//     }
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateExportPlugins(CCmdUI *pCmdUI)
{
   // pCmdUI->Enable(theApp.m_OgitorsRoot->IsSceneLoaded());
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUndoRedo(UINT id)
 {
//     if(OgitorsUndoManager::getSingletonPtr())
//     {
//         switch(id)
//         {
//         case ID_OGITOR_UNDO:OgitorsUndoManager::getSingletonPtr()->Undo();break;
//         case ID_OGITOR_REDO:OgitorsUndoManager::getSingletonPtr()->Redo();break;
//         }
//     }
}



//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateUndoRedo(CCmdUI *pCmdUI)
{
//     CString desc;
// 
//     if(OgitorsUndoManager::getSingletonPtr())
//     {
//         switch(pCmdUI->m_nID)
//         {
//         case ID_OGITOR_UNDO:
//             {
//                 pCmdUI->Enable(OgitorsUndoManager::getSingletonPtr()->CanUndo());
//                 desc = OgitorsUndoManager::getSingletonPtr()->GetUndoString().c_str();
//                 break;
//             }
//         case ID_OGITOR_REDO:
//             {
//                 pCmdUI->Enable(OgitorsUndoManager::getSingletonPtr()->CanRedo());
//                 desc = OgitorsUndoManager::getSingletonPtr()->GetRedoString().c_str();
//                 break;
//             }
//         }
//     }
//     else
//     {
//          pCmdUI->Enable(false);
//          desc = _T("");
//     }
//     
//     CMFCRibbonButton *Btn = (CMFCRibbonButton*)m_wndRibbonBar.FindByID(pCmdUI->m_nID,FALSE);
//     Btn->SetDescription(desc);
}
//------------------------------------------------------------------------------------
void CMainFrame::OnCustomGUI(UINT id)
{
    //gClientRootOnCustomGUI(id);
}
//------------------------------------------------------------------------------------
void CMainFrame::OnUpdateCustomGUI(CCmdUI *pCmdUI)
{
//     UpdateEvent evt = gClientRootOnUpdateCustomGUI(pCmdUI->m_nID);
//     if(evt.GetID() != -1)
//     {
//         pCmdUI->SetCheck(evt.GetChecked()?1:0);
//         pCmdUI->Enable(evt.GetEnabled()?1:0);
//         if(evt.GetWidget()->GetType() != WIDGET_EDIT)
//         {
//             CString caption(evt.GetCaption().c_str()); 
//             pCmdUI->SetText(caption);
//         }
//     }
}
void CMainFrame::OnMusicGUI(UINT id)
{
// 	switch(id)
// 	{
// 	case ID_MUSIC_BRUSHSIZE:
// 
// 	 
// 
// 		theApp.m_OgitorsRoot->GetSoundEditor()->SetPos(m_MusicLabel->GetPos());
// 
// 
// 
// 
// 		// 			if (theApp.m_OgitorsRoot->GetSoundEditor()&&m_MusicLabel )
// 		// 			{
// 		// 				m_MusicLabel->SetPos(theApp.m_OgitorsRoot->GetSoundEditor()->getPos());
// 		// 				
// 		// 				CString newlabel;
// 		// 				newlabel.Format(_T("(%d) second"),(int)theApp.m_OgitorsRoot->GetSoundEditor()->getPlayPos());
// 		// 				//newlabel.Format(_T("(%d) %"),(int)theApp.m_OgitorsRoot->GetSoundEditor()->getPos());
// 		// 				m_MusicSizeLabel->SetText(newlabel);
// 		// 			}
// 
// 		break;
// 
// 	case ID_TOOLS_PLAY:
// 		theApp.m_OgitorsRoot->GetCameraEditor()->play();
// 		theApp.m_OgitorsRoot->GetSoundEditor()->play();
// 		theApp.m_OgitorsRoot->GetAvatarEditor()->openPause();
// 		DlgEditMusic.m_bAvatarAnimation = true;
// 		break;
// 	case ID_TOOLS_PAUSE:
// 		theApp.m_OgitorsRoot->GetCameraEditor()->pause();
// 		theApp.m_OgitorsRoot->GetSoundEditor()->pause();
// 		theApp.m_OgitorsRoot->GetAvatarEditor()->pause();
// 		break;
// 	case ID_TOOLS_STOP:
// 		theApp.m_OgitorsRoot->GetCameraEditor()->stop();
// 		theApp.m_OgitorsRoot->GetSoundEditor()->stop();
// 		theApp.m_OgitorsRoot->GetAvatarEditor()->stop();
// 		break;
// 	case ID_TOOLS_SETMUSIC:
// 		//CDlgEditMusic DlgEditMusic;
// 
// 		DlgEditMusic.ShowWindow(SW_SHOW);
// 		
// 
// 	 
// 		 
// 		break;
// 		
// 	}

}

// 
// void CMainFrame::OnUpdateMusicGUI(CCmdUI *pCmdUI)
// {
// 	if (theApp.m_OgitorsRoot->GetAvatarEditor() != NULL)
// 	{
// 		pCmdUI->SetCheck(TRUE);
// 		pCmdUI->Enable(TRUE);
// 	}
// 	else
// 	{
// 		pCmdUI->Enable(FALSE);
// 
// 	}
// 	
// }

	 void CMainFrame::OnTimer(UINT nIDEvent)
	{
// 		if (theApp.m_OgitorsRoot->GetSoundEditor()&&m_MusicLabel )
// 		{
// 			m_MusicLabel->SetPos(theApp.m_OgitorsRoot->GetSoundEditor()->getPos());
//             float time  = theApp.m_OgitorsRoot->GetSoundEditor()->getPlayPos();
// 			CString newlabel;
// 			newlabel.Format(_T("(%f) second"),time);
// 			//newlabel.Format(_T("(%d) %"),(int)theApp.m_OgitorsRoot->GetSoundEditor()->getPos());
// 			m_MusicSizeLabel->SetText(newlabel);
// 
// 			if (theApp.m_OgitorsRoot->GetSoundEditor()->isplay())
// 			{
// 				float 	m_playAvaterTime = StringConverter::parseReal(ConvertToApoString(DlgEditMusic.m_stateTime));
// 				if ((int)time ==  (int)m_playAvaterTime)
// 				{
// 					if (DlgEditMusic.m_bAvatarAnimation == true)
// 					{
// 						theApp.m_OgitorsRoot->GetAvatarEditor()->play();
// 						DlgEditMusic.m_bAvatarAnimation = false;
// 					}
// 				}
// 			}
// 
// 			UpdateData(FALSE);
// 			m_wndRibbonBar.Invalidate();
// 
// // 			CPaintDC dc(this);
// // 			m_MusicSizeLabel->OnDraw(&dc);
// 			
// 		}
	}

//------------------------------------------------------------------------------------

